<template>
  <div class="zeus-collapse-item">
    <div class="title"
         @click="toggle">{{ title }}</div>
    <div class="content"
         v-if="open">
      <slot />
    </div>
  </div>
</template>

<script>
import { ref } from 'vue'
export default {
  props: {
    title: {
      type: String,
      require: true,
    },
  },
  setup () {
    let open = ref(false)
    const toggle = () => {
      open.value = !open.value
    }
    return {
      open,
      toggle
    }
  }
}
</script>

<style lang="scss">
$grey: #ddd;
$border-radius: 4px;
.zeus-collapse-item {
  > .title {
    border: 1px solid $grey;
    margin-top: -1px;
    margin-left: -1px;
    margin-right: -1px;
    min-height: 32px;
    display: flex;
    align-items: center;
    padding: 0 8px;
    background: lighten($grey, 8%);
  }
  &:first-child {
    > .title {
      border-top-left-radius: 4px;
      border-top-right-radius: 4px;
    }
  }
  &:last-child {
    > .title:last-child {
      border-bottom-left-radius: $border-radius;
      border-bottom-right-radius: $border-radius;
    }
  }
  > .content {
    padding: 8px;
  }
}
</style>
